package project.adapter;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.List;

import project.model.PrComment;

import android.content.Context;
import android.graphics.Color;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import approve.action.R;

public class ProjectCommentErrorAdapter extends BaseAdapter implements OnClickListener{
	Context context;
	List<PrComment> lstComment;
	
	public ProjectCommentErrorAdapter(Context context,List<PrComment> lstComment){
		this.context = context;
		this.lstComment = lstComment;
	}

	@Override
	public int getCount() {
		return lstComment.size();
	}

	@Override
	public Object getItem(int position) {
		return lstComment.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		PrComment pr = lstComment.get(position);
		String commentView ="";
		String txtTime = "";
		if(convertView==null){
			LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView=inflater.inflate(R.layout.adaptererr, null);
		}
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		TextView comment=(TextView)convertView.findViewById(R.id.valtitleError);
//		comment.setText(pr.getComment());
		commentView = pr.getCommentview();
		Spannable WordtoSpan = new SpannableString(commentView);        
		WordtoSpan.setSpan(new ForegroundColorSpan(Color.parseColor(pr.getColorText())), 0, commentView.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		comment.setText(WordtoSpan);
		
		TextView datetime = (TextView)convertView.findViewById(R.id.datet);
		datetime.setText(format.format(pr.getDateComment()) + "(" + pr.getNameEployee() +")");
//		datetime.setText(format.format(pr.getDateComment()) + "(" + pr.getEmployeeName() +")");
//		txtTime = format.format(pr.getDateComment());
//		WordtoSpan = new SpannableString(txtTime);
//		WordtoSpan.setSpan(new ForegroundColorSpan(Color.parseColor(pr.getColorText())), 0, txtTime.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//		datetime.setText(WordtoSpan);
		
		return convertView;
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		
	}

}
